<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Mayando.Web.ViewModels.GalleryViewModel>>" MasterPageFile="~/Views/Shared/Site.Master" %>

<asp:Content ID="title" ContentPlaceHolderID="TitleContent" runat="server">
    <%= Html.Encode(Resources.GalleriesTitle) %>
</asp:Content>

<asp:Content ID="content" ContentPlaceHolderID="MainContent" runat="server">
<div id="galleryindexpage">
    <h2><%= Html.Encode(Resources.GalleriesTitle) %></h2>
    <% if (Page.User.IsAdministrator()) { %>
    <script type="text/jscript" language="jscript">
        function doPost(id, direction) {
            var frm = document.getElementById("moveForm");
            frm.id.value = id;
            frm.direction.value = direction;
            frm.submit();
            return true;
        }
    </script>
    <% using(Html.BeginGalleriesMoveForm("moveForm")) { %>
        <%= Html.Hidden("id")%>
        <%= Html.Hidden("direction")%>
    <% } %>
    <% } %>
    <table class="list">
        <tbody>
        <% foreach(var galleryModel in Model) { %>
            <tr>
                <td>
                    <div class="photo-thumbnail">
                        <a href="<%= Url.GalleryDetails(galleryModel.Gallery) %>" title="<%= Html.AttributeEncode(galleryModel.Gallery.Title) %>">
                            <img src="<%= galleryModel.GetCoverPhotoUrl(Url.ThemedContent("~/Content/gallery.png")) %>" alt="<%= Html.AttributeEncode(galleryModel.Gallery.Title) %>" />
                        </a>
                    </div>
                </td>
                <td>
                    <div class="listitem" id="gallery-<%= galleryModel.Gallery.Id %>">
                        <div class="listitem-title">
                            <a href="<%= Url.GalleryDetails(galleryModel.Gallery) %>"><%= Html.Encode(galleryModel.Gallery.Title) %></a>
                        <% if (Page.User.IsAdministrator()) { %>
                           <%= Html.ActionLinkGalleryEdit("Edit", galleryModel.Gallery.Id, "admin") %>
                           <%= Html.ActionLinkGalleryDelete("Delete", galleryModel.Gallery.Id, "admin") %>
                           <a href="#" class="admin" onclick="doPost('<%= galleryModel.Gallery.Id %>','<%= Direction.Top.ToActionString() %>')">Top</a>
                           <a href="#" class="admin" onclick="doPost('<%= galleryModel.Gallery.Id %>','<%= Direction.Up.ToActionString() %>')">Up</a>
                           <a href="#" class="admin" onclick="doPost('<%= galleryModel.Gallery.Id %>','<%= Direction.Down.ToActionString() %>')">Down</a>
                           <a href="#" class="admin" onclick="doPost('<%= galleryModel.Gallery.Id %>','<%= Direction.Bottom.ToActionString() %>')">Bottom</a>
                        <% } %>
                        </div>
                        <div class="listitem-content"><%= galleryModel.Gallery.Description %></div>
                        <div class="listitem-footer"><%= Html.NumberOfPhotos(galleryModel.Photos.Photos.TotalItemCount) %></div>
                    </div>
                </td>
            </tr>
        <% } %>
        </tbody>
    </table>
</div>
</asp:Content>